package com.sort.animation;

import javax.swing.*;
import java.awt.*;


public class BiNode extends JLabel {

    private int value;

    private final static int WIDTH = 60;
    private final static int HEIGHT = 60;

    private volatile BiNodeStatus nodeStatus = BiNodeStatus.NORMAL;

    public BiNode(int value ,int x, int y) {
        super(value + "");
        this.value = value;
        setBounds(x,y,WIDTH,HEIGHT);
        Font font = new Font("Serif", Font.BOLD, 40); // 参数2为样式，参数3为大小
        setFont(font);
        setOpaque(true); // 确保背景色被填充
        setHorizontalAlignment(SwingConstants.CENTER);
        setVerticalAlignment(SwingConstants.CENTER);
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
        setText(value+"");
    }


    public BiNodeStatus getNodeStatus() {
        return nodeStatus;
    }

    public void setNodeStatus(BiNodeStatus nodeStatus) {
        this.nodeStatus = nodeStatus;
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        Graphics2D g2d = (Graphics2D) g.create();

        g2d.setColor(Color.RED);
        g2d.setStroke(new BasicStroke(3));
        g2d.drawOval(0, 0, WIDTH, HEIGHT);

        switch (nodeStatus){
            case NORMAL:
                setBackground(null);
                setForeground(Color.BLACK);
                break;
            case COMPARE:
                setBackground(Color.RED);
            case SWAP:
                setForeground(Color.BLUE);
                break;
            default:
                setBackground(null);
                break;
        }

        g2d.dispose();
    }


}
